package cn.house.houseai.mapper;

import cn.house.houseai.entify.Users;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;

/**
 * @author 羡y
 * @date 2024/9/27
 * @Description
 */
@Mapper
public interface UserMapper {
    @Select("select user_id,username,contact_number,address,account_info from users")
    List<Users> queryAll();

    //根据用户id查询用户
    @Select("select user_id, password,username, contact_number, address, account_info from users where user_id = #{user_id}")
    Users selectUserId(@Param("user_id") Integer user_id);

    Users selectUser(@Param("username") String username, @Param("password") String password);
    /**
     * 插入用户数据
     * @param user
     * @return
     */

    int insertUser(Users user);
    /**
     * 修改用户数据
     * @param user
     * @return
     */
    int updateUser(Users user);
    /**
     * 根据username查询员工信息
     * @param username
     * @return
     */
    @Select("select * from users where username =#{username}")
    Users getById(String username);

    @Update("UPDATE users SET password = #{newPassword} WHERE user_id = #{user_id}")
    int updatePassword(@Param("user_id") int user_id, @Param("newPassword") String newPassword);

    @Select("select password from users where user_id =#{user_id}")
    Users getByPassword(int user_id);
}
